<?php
// +----------------------------------------------------------------------
// | zhanshop-cloud / LogstashTest.php    [ 2025/1/20 13:02 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2011~2025 zhangqiquan All rights reserved.
// +----------------------------------------------------------------------
// | Author: zhangqiquan <768617998@qq.com>
// +----------------------------------------------------------------------
declare (strict_types=1);

namespace test;

use zhanshop\App;
use zhanshop\client\Httpclient;
use zhanshop\TestCase;

class LogstashTest extends TestCase
{
    public function testNginx()
    {
        $cloudUrl = 'http://127.0.0.1:'.(intval(App::config()->get('bridge.port')) - 1).'/v1/cloud.log/'.App::config()->get('bridge.token');
        var_dump($cloudUrl);
        $httpclient = new Httpclient();
        $httpclient->enableIpv6()->setTimeout(3000);
        $ok = $httpclient->setHeader('Content-Type', 'application/json')->request($cloudUrl, "POST", json_encode([
            'path' => "123.log",
            'body' => '{"timestamp":"2024-09-23T16:51:07+08:00","server_addr":"172.18.0.4","remote_addr":"192.168.65.1","host":"127.0.0.1","uri":"/+unix:/Users/zhangqiquan/.docker/run/docker.sock","body_bytes_sent":153,"request":"GET /+unix:///Users/zhangqiquan/.docker/run/docker.sock HTTP/1.1","request_length":190,"request_time":0.000,"status":"500","http_referer":"","http_user_agent":"python-requests/2.32.3"}',
        ]));
        var_dump($ok);
    }
}